import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class test4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int target= in.nextInt();
        System.out.println(containsNearbyDuplicate(arr, target));
    }
    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        HashMap<Integer,Integer> map = new HashMap<>();//<数值,下标>
        map.put(nums[0],0);
        for (int i = 1; i < nums.length; i++) {
            Integer flag = map.get(nums[i]);//获得下标
            if(flag!=null){
                if (i-flag<=k){
                    return true;
                }
            }
            map.put(nums[i],i );
        }
        return false;
    }
}
